package com.ptone.messagecenter.modules.msg.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ptone.messagecenter.common.base.PageForm;
import com.ptone.messagecenter.common.base.Result;
import com.ptone.messagecenter.common.utils.VerificationUtil;
import com.ptone.messagecenter.modules.msg.dto.MsgRecordsDTO;
import com.ptone.messagecenter.modules.msg.entity.MsgRecords;
import com.ptone.messagecenter.modules.msg.service.MsgRecordsService;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 消息记录：前端控制器
 *
 * @author:Lance
 */
@RestController
@RequestMapping("/msgRecords")
public class MsgRecordsController {

    @Resource
    private MsgRecordsService msgRecordsService;


    /**
     * 消息记录-insert
     *
     * @return
     * @throws BindException
     */
    @PostMapping("/insert")
    public Result<Boolean> insert(@RequestBody MsgRecordsDTO msgRecordsDTO) throws BindException {
        VerificationUtil.checkNull(msgRecordsDTO, "senderMobile", "readerMobile", "msgTemplate", "msgTemplateValue");
        return Result.success(msgRecordsService.insert(msgRecordsDTO));
    }


    /**
     * 消息记录-update
     *
     * @return
     * @throws BindException
     */
    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody MsgRecords entity) throws BindException {
        VerificationUtil.checkNull(entity, "id");
        return Result.success(msgRecordsService.update(entity));
    }

    /**
     * 消息记录-delete
     *
     * @return
     * @throws BindException
     */
    @PostMapping("/delete")
    public Result<Boolean> delete(@RequestBody MsgRecords entity) throws BindException {
        VerificationUtil.checkNull(entity, "id");
        return Result.success(msgRecordsService.delete(entity));
    }

    /**
     * 消息记录-info
     *
     * @return
     * @throws BindException
     */
    @PostMapping("/info")
    public Result<MsgRecords> info(@RequestBody MsgRecords entity) throws BindException {
        VerificationUtil.checkNull(entity, "id");
        return Result.success(msgRecordsService.info(entity));
    }

    /**
     * 消息记录-page
     *
     * @return
     * @throws BindException
     */
    @PostMapping("/page")
    public Result<IPage<MsgRecords>> page(@RequestBody PageForm<MsgRecords> form) throws BindException {
        VerificationUtil.checkNull(form);
        return Result.success(msgRecordsService.page(form));
    }

}
